export function map(mechanism_addr,dialogFormVisible,longitude,latitude) {
    var _this = this
    var longitude =  localStorage.getItem('longitude')
    var  latitude =  localStorage.getItem('latitude')
    var map = new BMap.Map("map");    // 创建Map实例
    var myGeo = new BMap.Geocoder();
    var point = new BMap.Point(longitude,latitude);
    var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {"input" : "suggestId"
        ,"location" : map
    });
    ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
	    var str = "";
		var _value = e.fromitem.value;
		var value = "";
        if (e.fromitem.index > -1) {
          value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        }    
		str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
		value = "";
        if (e.toitem.index > -1) {
          _value = e.toitem.value;
          value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        }    
		    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
		    G("searchResultPanel").innerHTML = str;
	    });
        var myValue;
	    ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
        console.log(e.item.value)
        G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
        setPlace();
      });
      function G(id) {
		    return document.getElementById(id);
	    }
      function setPlace(){
        map.clearOverlays();    //清除地图上所有覆盖物
        function myFun(){
          var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
          map.centerAndZoom(pp, 18);
          map.addOverlay(new BMap.Marker(pp));    //添加标注
        }
        var local = new BMap.LocalSearch(map, { //智能搜索
          onSearchComplete: myFun
        });
        local.search(myValue);
      }
	    map.centerAndZoom(point,19);
      var geolocation = new BMap.Geolocation();
      geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
          var mk = new BMap.Marker(r.point);
          map.addOverlay(mk);
          map.panTo(r.point);
        }else {
          alert('failed'+this.getStatus());
        }        
      },{enableHighAccuracy: true})
      map.addEventListener("click", function(e){  
        map.clearOverlays();      
        var pt = e.point;
        longitude =pt.lng
        latitude = pt.lat
        var marker = new BMap.Marker(new BMap.Point(longitude, latitude = pt.lat));
		map.addOverlay(marker);            //增加点
        myGeo.getLocation(pt, function(rs){
           
          var addComp = rs.addressComponents;
           mechanism_addr = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber
           dialogFormVisible  = true
           console.log(mechanism_addr,'000')
          // _this.Isshow = false
        });        
	});
      map.centerAndZoom(new BMap.Point(longitude, latitude), 19);// 添加带有定位的导航控件
      var navigationControl = new BMap.NavigationControl({// 靠左上角位置
        anchor: BMAP_ANCHOR_TOP_RIGHT,// LARGE类型
        type: BMAP_NAVIGATION_CONTROL_LARGE,// 启用显示定位
        enableGeolocation: true
      });
      map.addControl(navigationControl);// 添加定位控件
      var geolocationControl = new BMap.GeolocationControl();
      geolocationControl.addEventListener("locationSuccess", function(e){// 定位成功事件
        var address = '';
        address += e.addressComponent.province;
        address += e.addressComponent.city;
        address += e.addressComponent.district;
        address += e.addressComponent.street;
        address += e.addressComponent.streetNumber;
      });
      geolocationControl.addEventListener("locationError",function(e){// 定位失败事件
        alert(e.message);
      });
      map.addControl(geolocationControl);
      map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放	
    return {mechanism_addr,dialogFormVisible,longitude,latitude}
  }
  